package com.health.db.service.user.impl;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import com.health.db.dao.user.IGoodsPriceListDao;
import com.health.db.model.GoodsPriceList;
import com.health.db.model.GoodsPriceListTemp;
import com.health.db.service.user.IGoodsPriceListService;

public class GoodsPriceListServiceImpl implements IGoodsPriceListService {

	private IGoodsPriceListDao goodsPriceListDao ;
 
	//查询goods 医生应得 以及用户应付
	@Override
	public GoodsPriceListTemp selectByGoodsIdDocId(GoodsPriceList example) {
		// TODO Auto-generated method stub
		//查询列表，数据存储方式 医生入账以及用户出账拆开
		GoodsPriceListTemp temp = new GoodsPriceListTemp();
		if (example.getGoodsid()!=0&&StringUtils.isNotBlank(example.getSerialIdno())) {
			List<GoodsPriceListTemp> goodsPriceList=goodsPriceListDao.selectByGoodsIdDocId(example);
			
			//正常数据为1条或者两条
			if (goodsPriceList.size()<=2) {
				//col =2 医生入账  col =1 医生出账
				for (int i = 0; i < goodsPriceList.size(); i++) {
					GoodsPriceListTemp goodsPriceListTemp = goodsPriceList.get(i);
					
					//price为用户需要支付的费用  price00为医生收到的资费
					if (goodsPriceListTemp.getColumnid()==1) {
						//用户支付的价格
						temp.setPrice(goodsPriceListTemp.getPrice());
						//时间参数  商品对应的时间
						temp.setChargeQuantity(goodsPriceListTemp.getChargeQuantity());
					}else{
						//医生获得的价格
						temp.setPrice00(goodsPriceListTemp.getPrice());
					}
				}
				
			}
		}else if (example.getGoodsid()!=0) {
			List<GoodsPriceListTemp> goodsPriceList=goodsPriceListDao.selectByGoodsIdDocId(example);
			
			//正常数据为1条或者两条
			if (goodsPriceList.size()==1) {
				//col =2 医生入账  col =1 医生出账
					GoodsPriceListTemp goodsPriceListTemp = goodsPriceList.get(0);
					//price为用户需要支付的费用  price00为医生收到的资费
					if (goodsPriceListTemp.getColumnid()==1) {
						//用户支付的价格
						temp.setPrice(goodsPriceListTemp.getPrice());
						//时间参数  商品对应的时间
						temp.setChargeQuantity(goodsPriceListTemp.getChargeQuantity());
					}
			}
			
			
		}
		return temp;
	}

	@Override
	public GoodsPriceListTemp selectByGoodsIdDocIdSingle(GoodsPriceList example) {
		// TODO Auto-generated method stub
		if (null!=example.getColumnid()&&example.getColumnid()!=0) {
			
			List<GoodsPriceListTemp> goodsPriceList=goodsPriceListDao.selectByGoodsIdDocId(example);
			if (goodsPriceList.size()>0) {
				
				return goodsPriceList.get(0);
			}else{
				return null;
			}
		}else{
			return null;
		}
	}

	public IGoodsPriceListDao getGoodsPriceListDao() {
		return goodsPriceListDao;
	}

	public void setGoodsPriceListDao(IGoodsPriceListDao goodsPriceListDao) {
		this.goodsPriceListDao = goodsPriceListDao;
	}

	@Override
	public List<GoodsPriceListTemp> selectByDocIdForUserUsed(Long Serial_IDNO) {
		// TODO Auto-generated method stub
		GoodsPriceList example = new GoodsPriceList();
		example.setColumnid((short) 1);
		if (null!=Serial_IDNO) {
			example.setSerialIdno(String.valueOf(Serial_IDNO));
		}
		List<GoodsPriceListTemp> goodsPriceList=goodsPriceListDao.selectByGoodsIdDocId(example);
		return goodsPriceList;
		//return goodsPriceListDao.selectByDocIdForUserInUse(Serial_IDNO);
	}

}
